package math;

import org.junit.Test;

/*
 *@description 直线上最多的点数
 *@author hkfan
 *@version 1.0
 *@create 2025/6/23 16:50
 */
public class LeetCode_149 {

    @Test
    public void test(){
        System.out.println(maxPoints(new int[][]{
                new int[]{0,0},
                new int[]{1,-1},
                new int[]{1,1},
//                new int[]{4,1},
//                new int[]{2,3},
//                new int[]{1,4},
        }));
    }

    public int maxPoints(int[][] points) {
        if (points.length<=1){
            return points.length;
        }
        Integer res = 0;

        for (int i = 0; i < points.length; i++) {

            for (int j = i+1; j < points.length; j++) {
                int temp=2;
                double m=Integer.MIN_VALUE ;
                if (points[j][0]!=points[i][0]){
                    m=(points[j][1]-points[i][1])*1.0/(points[j][0]-points[i][0]);
                }
                for (int k = j+1; k < points.length; k++) {
                    if (m==Integer.MIN_VALUE&&points[k][0]==points[i][0]){
                        temp++;
                    } else if (points[k][0]!=points[i][0]&&(points[k][1]-points[i][1])*1.0/(points[k][0]-points[i][0])==m) {
                        temp++;
                    }
                }
                res=Math.max(res,temp);
            }
        }

        return res;
    }

}
